<?php
include("conn.inc");
include("functions.inc.php");
session_start();
  
//Smarty Settings :Start
require('./include/smarty/libs/Smarty.class.php');  // put full path to Smarty.class.php
$smarty = new Smarty();

$smarty->setTemplateDir('./templates');
$smarty->setCompileDir ('./include/smarty/omTemplates_c');
$smarty->setCacheDir   ('./include/smarty/omCache');
$smarty->setConfigDir  ('./include/smarty/omConfigs');
//Smarty Settings :End
date_default_timezone_set ("Asia/Calcutta");
if(isset($_SESSION['s_userId']))
{
  $selUsermenuArr = array();
  $i=0;
  	
  $selType="SELECT userType
              FROM user
             WHERE userId=".$_SESSION['s_userId'];
  
  $selTypeRes=mysql_query($selType);
  
  $selTypeResRow=mysql_fetch_array($selTypeRes);

  if($selTypeResRow['userType'] == 'Admin')
  {
    $selUsermenu="SELECT menuId,menuName,menuDisplay
  	                FROM menu";
  	                
    $selUsermenuRes=mysql_query($selUsermenu);   
  
    while($selUsermenuResRow=mysql_fetch_array($selUsermenuRes))
    {
    	$selUsermenuArr[$i]['menuName']     = $selUsermenuResRow['menuName'];
    	$selUsermenuArr[$i]['menuId']       = $selUsermenuResRow['menuId'];
    	$selUsermenuArr[$i]['menuDisplay']  = $selUsermenuResRow['menuDisplay'];
    	$i++;
    }
  }
  else
  {
  	
    $selUsermenu="SELECT DISTINCT(a.menuId), b.menuName ,b.menuId,b.menuDisplay
                    FROM usermenu a
                    JOIN menu b ON a.menuId = b.menuId
                   WHERE userId=".$_SESSION['s_userId'];
     
    $selUsermenuRes=mysql_query($selUsermenu);   
    
    while($selUsermenuResRow=mysql_fetch_array($selUsermenuRes))
    {
    	$selUsermenuArr[$i]['menuName']      = $selUsermenuResRow['menuName'];
    	$selUsermenuArr[$i]['menuId']        = $selUsermenuResRow['menuId'];
    	$selUsermenuArr[$i]['menuDisplay']   = $selUsermenuResRow['menuDisplay'];
    	$i++;
    }               
  }
  $smarty->assign("selUsermenuArr",$selUsermenuArr);
}
?>